package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.anno.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

//@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     *
     * @param id
     * @return
     */
    @Select("select count(id) from dish where category_id = #{id}")
    //获取主键值并赋值给id属性
    Integer countByCategoryId(Long id);

    /**
     * 插入菜品数据
     *
     * @param dish
     */
    @AutoFill(OperationType.INSERT) //插入数据时自动填充创建时间和更新时间
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into dish values" +
            " (null,#{name}, #{categoryId}, #{price}, #{image},#{description}," +
            "#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void insert(Dish dish);

    /**
     * 菜品分页查询
     *
     * @param dto
     * @return
     */
    Page<DishVO> list(DishPageQueryDTO dto);

    /**
     * 根据id查询菜品信息
     *
     * @param id
     * @return
     */
    Dish selectById(Long id);

    /**
     * 批量删除菜品
     *
     * @param Ids
     */
    void deleteBatch(List<Long> Ids);

    /**
     * 修改菜品信息
     *
     * @param dish
     */
    @AutoFill(OperationType.UPDATE)
    void update(Dish dish);



    /**
     * 根据分类d查询菜品
     * @param dish
     * @return
     */
    List<Dish> selectByCategoryId(Dish dish);


}
